using System.Globalization;
using System.Windows.Data;

namespace Koala.Pro.Helpers;

public class BooleanConverter<T> : IValueConverter
{
    public T TrueValue { get; set; }

    public T FalseValue { get; set; }

    public BooleanConverter(T trueValue, T falseValue)
    {
        TrueValue = trueValue;
        FalseValue = falseValue;
    }

    public virtual object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        bool flag = default(bool);
        int num;
        if (value is bool)
        {
            flag = (bool)value;
            num = 1;
        }
        else
        {
            num = 0;
        }
        return (((uint)num & (flag ? 1u : 0u)) != 0) ? TrueValue : FalseValue;
    }

    public virtual object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        return value is T x && EqualityComparer<T>.Default.Equals(x, TrueValue);
    }
}
